package com.kuangstudy.controller.archives;

import com.kuangstudy.service.archives.IArchivesService;
import com.kuangstudy.vo.ArticleYearVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * @author zhangfushuai
 * @description 文章归档
 * @since 2022/4/18 11:13
 **/
@Controller
public class ArchivesController {

    @Autowired
    private IArchivesService archivesService;

    /**
     * @author zhangfushuai
     * @description 跳转到文章归档页面
     * @since 2022/4/18 11:14
     * 参数
     * @return org.springframework.web.servlet.ModelAndView
     **/
    @GetMapping(value = {"/archives", "/acv"})
    public ModelAndView toArchives() {
        // 1: 创建modelandview实例
        ModelAndView modelAndView = new ModelAndView();
        // 2: 指定返回的页面视图
        modelAndView.setViewName("archives/archives");
        // 3: 返回
        return modelAndView;
    }


    /**
     * @author zhangfushuai
     * @description 异步加载归档文章数据
     * @since 2022/4/18 11:46
     * 参数
     * @return java.util.List<com.kuangstudy.vo.ArticleYearVo>
     **/
    @GetMapping("/archives/load")
    @ResponseBody
    public List<ArticleYearVo> queryBlogsVo() {
        return archivesService.queryBlogsVo();
    }

    /**
     * @author zhangfushuai
     * @description 异步加载更多归档文章数据
     * @since 2022/4/18 11:47
     * 参数 year
     * 参数 pageNo
     * 参数 pageSize
     * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     **/
    @GetMapping("/archives/loadmore")
    @ResponseBody
    public List<Map<String, Object>> loadMore(Integer year,
                                              @RequestParam(defaultValue = "1") Integer pageNo,
                                              @RequestParam(defaultValue = "6") Integer pageSize) {
        return archivesService.findBlogByYear(year, pageNo, pageSize);
    }

}
